import { _decorator, Component, Label, Layout, Node, ScrollView, Slider, Sprite, Toggle, Vec2, Vec3 } from 'cc';
import { UIManager } from '../UIManager';
import { LanauageManager } from '../LanauageManager';
import { GameData, shopCfg } from '../GameData';
import { HttpClient } from '../net/HttpClient';
import { EventManager } from '../EventManager';
import { AudioMgr } from '../AudioMgr';
import { Util } from '../Util';
const { ccclass, property } = _decorator;

@ccclass('popupShopNew')
export class popupShopNew extends Component {

    @property(Sprite)
    shopSp:Sprite = null;

    @property(Label)
    coinLab:Label = null;

    selectId:number = 5;

    shopCfg:shopCfg;
    
    onEnable() {
        this.refresh();
    }

    refresh(){
        this.shopCfg = GameData.getItemDataByIdAndCfgs(this.selectId, GameData.shopCfgs);
        if (!this.shopCfg){
            return;
        }

        Util.loadSprite("imag/shop/" + this.shopCfg.lv, this.shopSp);

        this.coinLab.string = this.shopCfg.openCoin + "";
    }

    onClickHandler(event:Event, str:string){
        if (str == "newBtn"){
            if (!Util.isEnoughCoin(this.shopCfg.openCoin)){
                return;
            }
            HttpClient.getInstance().sendOpenShop(this.shopCfg.id, ()=>{
                UIManager.showTip("开店成功");
                UIManager.close(this.node);
            })
        }
        else if (str == "tog1"){
            this.selectId = 1;
        }
        else if (str == "tog2"){
            this.selectId = 2;
        }
        else if (str == "tog3"){
            this.selectId = 3;
        }
        else if (str == "tog4"){
            this.selectId = 4;
        }
        else if (str == "tog5"){
            this.selectId = 5;
        }
        this.refresh();
    }
}

